package cn.bluedot.framework.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 	通用返回类
 * @author Administrator
 *
 */
public class Message {
	//状态码
	private int code;
	//提示信息
	private String message;
	
	//用户要返回的数据
	private Map<String, Object> extend = new HashMap<String, Object>();

	/**
	 * 常用处理成功的信息
	 * @return
	 */
	public static Message success() {
		Message result = new Message();
		result.setCode(100);
		result.setMessage("处理成功！");
		
		return result;
	}
	
	/**
	 * 常用处理失败的信息
	 * @return
	 */
	public static Message fail() {
		Message result = new Message();
		result.setCode(200);
		result.setMessage("处理失败！");
		
		return result;
	}
	
	/**
	 * 获取存入数据map中的指定键值
	 * @param key
	 * @return
	 */
	public Object getObject(String key) {
		return key == null ? null : this.extend.get(key);
	}
	
	/**
	 * 添加
	 * @param key
	 * @param value
	 * @return
	 */
	public Message add(String key,Object value) {
		this.getExtend().put(key, value);
		return this;
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Map<String, Object> getExtend() {
		return extend;
	}

	public void setExtend(Map<String, Object> extend) {
		this.extend = extend;
	}
	
}
